-module(test).
-export([start/0, demo/0]).

%% 依赖的模块:
%% 1. stringprep, 需要调用stringprep:start()或者stringprep_sup:start_link()
%% 2. dynamic_compile
%% 3. logger

%% <1> ejabberd.cfg里面的每一项都是一个Erlang Term
%% a.  所有的Term必须以点(.)结尾
%% b.  格式如下:
%%     override_global.
%%     {loglevel, 4}.                
%%     [http_poll, web_admin, tls].  
%%     {language, "en"}.
%%     {ldap_rootdn, "dc=example, dc=com"}.
%%     {hosts, ["jabber.example.net", "im.example.com"]}.

%% <2> override stored options - 覆盖已有的options的"规则"
%% override_global - 在所有的Erlang nodes上起作用
%% override_local  - 在本地起作用
%% override_acls   - 在我们添加新的内容到access control lists的时候删除原来的数据

%% <3> authenticate - 用户认证的机制, 默认是internal mnesia database
%% {auth_method, internal}.
%%
%% 也可以修改成
%% {auth_method, odbc}.
%% 修改之后需要设置database setup section, 如果使用mysql, 可以这样设置:
%% {odbc_server, {mysql, "server", "database", "username", "password"}}.
%%

%% <4> Access Control Lists - xmpp account权限控制
%% admin权限
%% {acl, admin, {user, "aleksey", "localhost"}}.
%% {acl, admin, {user, "ermine", "example.org"}}.
%%
%% Blocked users
%% {acl, blocked, {user, "baduser", "example.org"}}.
%% {acl, blocked, {user, "test"}}.

%% <5> Access Rules - 访问规则
%% Maximum number of offline messages that users can have:
%% {access, max_user_offline_messages, [{5000, admin}, {100, all}]}.
%% This rule allows access only for local users:
%% {access, local, [{allow, local}]}.

start() ->
    stringprep_sup:start_link(),

    %% 创建config, local_config, acl三张表
    mnesia:stop(),
    mnesia:delete_schema([node()]),
    mnesia:create_schema([node()]),
    mnesia:start(),
    acl:start(),
    ejabberd_config:start().

demo() ->
    io:format("~p~n", [ejabberd_config:get_global_option(hosts)]).
